package com.hst.capacity.infra.convertor;

import com.hst.capacity.domain.common.constants.Constants;
import com.hst.capacity.domain.model.entity.driver.DriverAccountEntity;
import com.hst.capacity.domain.model.entity.driver.DriverCertificateEntity;
import com.hst.capacity.domain.model.entity.driver.DriverEntity;
import com.hst.capacity.domain.model.entity.driver.DriverProfileEntity;
import com.hst.capacity.domain.model.entity.vehicle.VehicleEntity;
import com.hst.capacity.domain.model.entity.vehicle.VehicleTypeEntity;
import com.hst.capacity.domain.model.request.dispatch.DispatchPartyDriverParam;
import com.hst.capacity.domain.model.request.driver.DriverAddCertificateParam;
import com.hst.capacity.domain.model.request.driver.DriverAddParam;
import com.hst.capacity.domain.model.request.driver.SaveAccountParam;
import com.hst.capacity.domain.model.request.elong.order.ElongOrderParam;
import com.hst.capacity.domain.model.response.PagingResultVO;
import com.hst.capacity.domain.model.response.driver.DriverInfoVO;
import com.hst.capacity.domain.model.response.driver.DriverPagingVO;
import com.hst.capacity.domain.model.response.fleet.FleetSearchDriverVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 *  司机运营的POJO属性转换器
 *
 * @author Hans
 * */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface DriverConvertor {

    DriverConvertor INSTANCE = Mappers.getMapper(DriverConvertor.class);

//    /**
//     * 入参转实体
//     *
//     * @param param
//     * @return
//     */
//    @Mapping(target = "driverCode", source = "mobile")
//    @Mapping(target = "driverMobile", source = "mobile")
//    @Mapping(target = "driverProfile.realName", source = "fullName")
//    @Mapping(target = "driverProfile.idCardNo", source = "idCard")
//    @Mapping(target = "driverProfile.familyAddress", source = "address")
//    DriverEntity convert(DriverAddParam param);

//    @Mapping(target = "realName", source = "fullName")
//    @Mapping(target = "idCardNo", source = "idCard")
//    @Mapping(target = "familyAddress", source = "address")
//    DriverProfileEntity convertToProfile(DriverAddParam param);

//    /**
//     * 实体转VO
//     * */
//    @Mapping(target = "realName", source = "driverProfile.realName")
//    @Mapping(target = "cityCode", source = "regionCode")
//    // @Mapping(target = "cars", source = "driverCar")
//    DriverPagingVO convert(DriverEntity driverEntity);

    /**
     * 分页检索结果实体转VO
     *
     * */
    PagingResultVO<DriverPagingVO> convert(PagingResultVO<DriverEntity> source);

    /**
     * 编辑司机信息查询
     *
     * */
    @Mapping(target = "fullName", source = "profileEntity.realName")
    @Mapping(target = "mobile", source = "driverEntity.driverMobile")
    @Mapping(target = "idCard", source = "profileEntity.idCardNo")
    @Mapping(target = "address", source = "profileEntity.familyAddress")
    @Mapping(target = "serviceScope", source = "profileEntity.serviceScope")
    @Mapping(target = "qrcode", source = "profileEntity.qrcode")
    DriverAddParam convert(DriverEntity driverEntity,DriverProfileEntity profileEntity);

    List<FleetSearchDriverVO> convertSearchDriver(List<FleetSearchDriverVO> content);

    @Mapping(target = "driverMobile", source = "addParam.mobile")
    void convert(@MappingTarget DriverEntity driverEntity, DriverAddParam addParam);

    @Mapping(target = "driverMobile", source = "addParam.mobile")
    DriverEntity convert(DriverAddParam addParam);

    @Mapping(target = "realName", source = "addParam.fullName")
    @Mapping(target = "idCardNo", source = "addParam.idCard")
    @Mapping(target = "familyAddress", source = "addParam.address")
    @Mapping(target = "licenseTime",dateFormat = Constants.DATE_FORMAT)
    @Mapping(target = "licenseEnd",dateFormat = Constants.DATE_FORMAT)
    @Mapping(target = "licenseStart",dateFormat = Constants.DATE_FORMAT)
    void convert(@MappingTarget DriverProfileEntity driverProfileEntity, DriverAddParam addParam);

    void convert(@MappingTarget DriverAccountEntity driverAccountEntity, SaveAccountParam param);

    SaveAccountParam convert(DriverAccountEntity find);

    DriverAddCertificateParam convert(DriverCertificateEntity byIdDriver);

//    List<String> convert(List<VehicleEntity> vehicleEntities);
//    @Mapping(target = "empty", source = "vehicleEntities.plateNumber")
//    String convert(VehicleEntity vehicleEntities);
//    /**
//     * 转司机车辆绑定返回VO
//     */
//    @Mapping(target = "plateNumber", source = "vehicleEntity.plateNumber")
//    @Mapping(target = "idVehicleType", source = "vehicleEntity.idVehicleType")
//    @Mapping(target = "fuel", source = "vehicleEntity.profileEntity.fuel")
//    @Mapping(target = "passengerCapacity", source = "vehicleEntity.profileEntity.passengerCapacity")
//    DriverBandCarVO convertBandCarVo(DriverEntity driverEntity);

    DriverInfoVO convert2Info(DriverEntity entity);

    @Mapping(target = "idDriver", source = "idDriver")
    @Mapping(target = "realName", source = "driverName")
    @Mapping(target = "color", source = "vehicleColor")
    @Mapping(target = "model", source = "vehicleModel")
    @Mapping(target = "brand", source = "vehicleBrand")
    DriverInfoVO convert2Info(ElongOrderParam param);

//    @Mapping(target = "color", source = "color")
//    @Mapping(target = "model", source = "model")
//    @Mapping(target = "brand", source = "brand")
//    @Mapping(target = "plateNumber", source = "plateNumber")
    @Mapping(target = "realName", source = "driverName")
    @Mapping(target = "driverMobile", source = "mobile")
    DriverInfoVO convert2Info(DispatchPartyDriverParam param);

//    /**
//     * 编辑司机信息查询
//     *
//     * */
//    @Mapping(target = "idVehicle", source = "driverEntity.idVehicle")
//    DriverInfoVO convert2Driver(DriverEntity driverEntity,
//                               DriverProfileEntity profileEntity,
//                               VehicleEntity vehicleEntity,
//                               VehicleTypeEntity vehicleTypeEntity);

}
